/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.yuhanginfo.modules.sys.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.yuhanginfo.common.config.Global;
import com.yuhanginfo.common.persistence.Page;
import com.yuhanginfo.common.web.BaseController;
import com.yuhanginfo.common.utils.StringUtils;
import com.yuhanginfo.modules.sys.entity.InvoiceInfo;
import com.yuhanginfo.modules.sys.service.InvoiceInfoService;

/**
 * 发票管理
 * @author yangs
 * @version 2017-09-19
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/invoiceInfo")
public class InvoiceInfoController extends BaseController {

	@Autowired
	private InvoiceInfoService invoiceInfoService;
	
	@ModelAttribute
	public InvoiceInfo get(@RequestParam(required=false) String id) {
		InvoiceInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = invoiceInfoService.get(id);
		}
		if (entity == null){
			entity = new InvoiceInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:invoiceInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(InvoiceInfo invoiceInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<InvoiceInfo> page = invoiceInfoService.findPage(new Page<InvoiceInfo>(request, response), invoiceInfo); 
		model.addAttribute("page", page);
		return "modules/sys/invoiceInfoList";
	}

	@RequiresPermissions("sys:invoiceInfo:view")
	@RequestMapping(value = "form")
	public String form(InvoiceInfo invoiceInfo, Model model) {
		model.addAttribute("invoiceInfo", invoiceInfo);
		return "modules/sys/invoiceInfoForm";
	}

	@RequiresPermissions("sys:invoiceInfo:edit")
	@RequestMapping(value = "save")
	public String save(InvoiceInfo invoiceInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, invoiceInfo)){
			return form(invoiceInfo, model);
		}
		invoiceInfoService.save(invoiceInfo);
		addMessage(redirectAttributes, "保存订单详情成功");
		return "redirect:"+Global.getAdminPath()+"/sys/invoiceInfo/?repage";
	}
	
	@RequiresPermissions("sys:invoiceInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(InvoiceInfo invoiceInfo, RedirectAttributes redirectAttributes) {
		invoiceInfoService.delete(invoiceInfo);
		addMessage(redirectAttributes, "删除订单详情成功");
		return "redirect:"+Global.getAdminPath()+"/sys/invoiceInfo/?repage";
	}

}